<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- <button>click</button>

    <img src="../20211013/img/logo.png" alt=""> -->
<script>
    // 异步回调

    // 等待一段逻辑执行完成以后，再去执行另一段逻辑
    // promise


    let a = 100
    let b = 20

    let func = function () {
        // 回调函数
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                console.log(a)

                if (a === 100) {
                    reject('这里是一段失败的代码')
                } else {
                    resolve(123)
                }
            })
        })
    }

    // 必须等待func中的逻辑执行完毕以后，才能执行then中的逻辑
    // promise中必须resolve回调
    func().then(function (data) {
        console.log('回调参数', data)
        console.log(b)
    }).catch(function (err) {
        console.log('err', err)
    })

    // setTimeout(() => {
    //     console.log(a)
    // })

    // console.log(b)


</script>

</body>
</html>